//
//  TagCell.m
//  NiuBi
//
//  Created by chuangjia on 8/10/2015.
//  Copyright © 2015 Danpin Inc. All rights reserved.
//

#import "NiubiTagCell.h"
#import "ZShare.h"
#import "AOTag.h"

@interface NiubiTagCell ()<AOTagDelegate>
{
    
}
@property (nonatomic, strong) AOTagList *tagList;
@property(nonatomic,strong) UIView *bgView;
@end
@implementation NiubiTagCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        _bgView =[[UIView alloc] initWithFrame:self.bounds];
        _bgView.backgroundColor=[UIColor clearColor];
        [self.contentView addSubview:_bgView];
        _tagList = [[AOTagList alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH, 80)];
        _tagList.backgroundColor =[UIColor clearColor];
        _tagList.delegate=self;
        [_bgView addSubview:_tagList];
        
    }
    return self;
}
-(void)dealloc
{
    self.bgView =nil;
    self.data=nil;
    self.key=nil;
    self.tagList.delegate =nil;
    self.tagList=nil;
//  NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _bgView.frame=self.bounds;
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    NSArray *tagAr =(NSArray *)model;
    self.data =model;
    
    self.indexPath =indexPath;
    
    [self.tagList removeAllTag];
    
    float fTop = [self.tagList addTags:tagAr limitLine:[ZShare sharedInstance].lineCount type:@"NiubiTagCell"];
    _tagList.frame =CGRectMake(PHOTO_TIME_PADDING, 0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH,fTop);
    [self layoutSubviews];
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    NSArray *tagAr =(NSArray *)model;
    AOTagList *tc = [[AOTagList alloc] initWithFrame:CGRectMake(PHOTO_TIME_PADDING, 0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH, 80)];
    float fTop = [tc addTags:tagAr limitLine:[ZShare sharedInstance].lineCount type:@"NiubiTagCell"];
    tc=nil;
    return fTop+PHOTO_TIME_PADDING;
}
- (void)tagDidSelectTag:(AOTag *)tag
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_tag,self,tag.tTitle,nil,self.indexPath);
    }
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
@end